﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Net.Fan.SmallPig.BusinessRules;
using System.Data;
using Net.Fan.SmallPig.Common;

public partial class User_Administrators : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PagePermission.CheckIsAdmin(this);

        if (IsPostBack == false)
        {
            rebindAdministrators();
        }
    }

    private void rebindAdministrators()
    {
        DataTable admins = GroupBiz.GetAdministrators();
        ListBox1.DataSource = admins;
        ListBox1.DataBind();
    }

    protected void ButtonDel_Click(object sender, EventArgs e)
    {
        Result r = GroupBiz.DelAdministrator(ListBox1.SelectedValue);
        if (r.ResultType == ResultType.OK)
        {
            rebindAdministrators();
            LabelMessage.Text = null;
        }
        else
        {
            LabelMessage.Text = r.Message;
        }

    }
    protected void ButtonAdd_Click(object sender, EventArgs e)
    {
        GroupBiz.AddAdministrator(TextBoxNew.Text.Trim());
        rebindAdministrators();

    }
}
